﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

using System.IO;
using H2.NET.Data.Exceller;



namespace H2.NET.Web.Pages
{
    public partial class PSPM : TaskPage
    {
        #region 属性 Public

        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }
        private bool Status
        {
            get
            {
                return ViewState["Status"] == null ? false : (bool)ViewState["Status"];
            }
            set { ViewState["Status"] = value; }
        }
        public string Key
        {
            get
            {
                return ViewState["Key"] == null ? "" : (string)ViewState["Key"];

            }
            set { ViewState["Key"] = value; }
        }
        #endregion

        #region 事件 Page_Load(页面加载)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //bool flg = TaskAPI.IsAllowSubmit;
            bool flg = ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit) ? true : false;
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("00", "SOLD TO NO-SAP<br/>客户SAP编号", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sap_Code", InputType.None, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("01", "Customer Name<br/>客户中文名称", BoundColumnType2.TextBox, 200, Align.Left, false, "Sold_CN_Name", InputType.None, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("02", "原销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "Old_Sap_Code", InputType.None, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("03", "原销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "Old_CN_Name", InputType.None, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("04", "新销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "New_Sap_Code", InputType.None, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("05", "新销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "New_CN_Name", InputType.None, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("06", "New E-Mail Address<br/>邮箱地址", BoundColumnType2.TextBox, 160, Align.Left, flg, "E_Mail", InputType.None, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("07", "New Phone<br/>手机号码", BoundColumnType2.TextBox, 100, Align.Left, flg, "Tel", InputType.Numeric, null));
            gv_Sales_K1.DynamicColumn.Add(new BoundColumn2("08", "Vendor Code", BoundColumnType2.TextBox, 80, Align.Left, false, "Vendor_Code", InputType.None, null));


            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("00", "SOLD TO NO-SAP<br/>客户SAP编号", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sap_Code", InputType.None, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("01", "Customer Name<br/>客户中文名称", BoundColumnType2.TextBox, 200, Align.Left, false, "Sold_CN_Name", InputType.None, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("02", "原销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "Old_Sap_Code", InputType.None, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("03", "原销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "Old_CN_Name", InputType.None, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("04", "新销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "New_Sap_Code", InputType.None, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("05", "新销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "New_CN_Name", InputType.None, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("06", "New E-Mail Address<br/>邮箱地址", BoundColumnType2.TextBox, 160, Align.Left, flg, "E_Mail", InputType.None, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("07", "New Phone<br/>手机号码", BoundColumnType2.TextBox, 100, Align.Left, flg, "Tel", InputType.Numeric, null));
            gv_Sales_K2.DynamicColumn.Add(new BoundColumn2("08", "Vendor Code", BoundColumnType2.TextBox, 80, Align.Left, false, "Vendor_Code", InputType.None, null));

            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("00", "SOLD TO NO-SAP<br/>客户SAP编号", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sap_Code", InputType.None, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("01", "Customer Name<br/>客户中文名称", BoundColumnType2.TextBox, 200, Align.Left, false, "Sold_CN_Name", InputType.None, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("02", "原销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "Old_Sap_Code", InputType.None, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("03", "原销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "Old_CN_Name", InputType.None, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("04", "新销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "New_Sap_Code", InputType.None, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("05", "新销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "New_CN_Name", InputType.None, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("06", "New E-Mail Address<br/>邮箱地址", BoundColumnType2.TextBox, 160, Align.Left, flg, "E_Mail", InputType.None, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("07", "New Phone<br/>手机号码", BoundColumnType2.TextBox, 100, Align.Left, flg, "Tel", InputType.Numeric, null));
            gv_Sales_K3.DynamicColumn.Add(new BoundColumn2("08", "Vendor Code", BoundColumnType2.TextBox, 80, Align.Left, false, "Vendor_Code", InputType.None, null));

            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("00", "SOLD TO NO-SAP<br/>客户SAP编号", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sap_Code", InputType.None, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("01", "Customer Name<br/>客户中文名称", BoundColumnType2.TextBox, 200, Align.Left, false, "Sold_CN_Name", InputType.None, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("02", "原销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "Old_Sap_Code", InputType.None, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("03", "原销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "Old_CN_Name", InputType.None, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("04", "新销售SAP编号", BoundColumnType2.TextBox, 60, Align.Left, flg, "New_Sap_Code", InputType.None, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("05", "新销售中文姓名", BoundColumnType2.TextBox, 70, Align.Left, false, "New_CN_Name", InputType.None, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("06", "New E-Mail Address<br/>邮箱地址", BoundColumnType2.TextBox, 160, Align.Left, flg, "E_Mail", InputType.None, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("07", "New Phone<br/>手机号码", BoundColumnType2.TextBox, 100, Align.Left, flg, "Tel", InputType.Numeric, null));
            gv_Sales_K1K2.DynamicColumn.Add(new BoundColumn2("08", "Vendor Code", BoundColumnType2.TextBox, 80, Align.Left, false, "Vendor_Code", InputType.None, null));

            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;
                InitControls();
                InitDropDownList();
                SetForeColor(Color.Blue, Sales_Group_L, Type_L, Sales_Division_L, Sales_Office_L, Region_L);
                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {

                }
                #endregion
                #region 审批环节
                else
                {
                    #region 加载数据并显示
                    mdc_spm_Sales_2 spm_Sales_1 = (mdc_spm_Sales_2.process == TaskAPI.Process & mdc_spm_Sales_2.incident == TaskAPI.Incident).ListFirst<mdc_spm_Sales_2>();
                    if (spm_Sales_1 != null)
                    {
                        ApplicationNo.Text = spm_Sales_1.ApplicationNo;
                        //VD.Checked                          = vendor.VD_Checked == "1";
                        //SA.Checked = vendor.SA_Checked == "1";
                        //VD_Category.SelectedValue = spm_Sales_1.Type;
                        //VD_Region.SelectedValue =spm_Sales_1.Sales_Region;
                        //VD_Sales_Office.SelectedValue = spm_Sales_1.Sales_Office_1;
                        if (!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit)
                        {
                            if (TaskAPI.Step != "CA Check" || !TaskAPI.IsAllowSubmit)
                            {
                                VD_Category.Items.Clear();
                                if (spm_Sales_1.Type == "1")
                                {
                                    VD_Category.Items.Add(new ListItem("1, 替换", "1"));
                                }
                                else if (spm_Sales_1.Type == "2")
                                {
                                    VD_Category.Items.Add(new ListItem("2, 增加", "2"));
                                }
                                else if (spm_Sales_1.Type == "3")
                                {
                                    VD_Category.Items.Add(new ListItem("3, 删除", "3"));
                                }
                                else if (spm_Sales_1.Type == "4")
                                {
                                    VD_Category.Items.Add(new ListItem("4, 修改销售员信息", "4"));
                                }
                                else
                                {
                                    VD_Category.Items.Add(new ListItem("    ", "0"));
                                }
                            }
                            VD_Region.Items.Clear();
                            VD_Region.Items.Add(new ListItem(spm_Sales_1.Sales_Region, spm_Sales_1.Sales_Region));
                            VD_Sales_Office.Items.Clear();
                            VD_Sales_Office.Items.Add(new ListItem(spm_Sales_1.Sales_Office_1, spm_Sales_1.Sales_Office_1));

                        }
                        VD_Category.SelectedValue = spm_Sales_1.Type;
                        DrpPriority.SelectedValue = spm_Sales_1.DrpPriority;
                        DMO_DrpPriority.SelectedValue = spm_Sales_1.DMO_DrpPriority;
                        VD_Region.SelectedValue = spm_Sales_1.Sales_Region;
                        VD_Sales_Office.SelectedValue = spm_Sales_1.Sales_Office_1;
                        Vd_Ka.Checked = spm_Sales_1.KA == "1";
                        Vd_Kc.Checked = spm_Sales_1.KC.Trim() == "1";
                        Vd_Kd.Checked = spm_Sales_1.KD.Trim() == "1";
                        Vd_Ki.Checked = spm_Sales_1.KI == "1";
                        Vd_Kg.Checked = spm_Sales_1.KG == "1";
                        Vd_Kh.Checked = spm_Sales_1.KH == "1";
                        Vd_Kha.Checked = spm_Sales_1.KHA == "1";
                        Vd_Ke.Checked = spm_Sales_1.KE == "1";
                        Vd_Kf.Checked = spm_Sales_1.KF == "1";
                        Vd_Salesperson_Division_K1.Checked = spm_Sales_1.Divison_K1 == "1";
                        Vd_Salesperson_Division_K2.Checked = spm_Sales_1.Divison_K2 == "1";
                        Vd_Salesperson_Division_K3.Checked = spm_Sales_1.Divison_K3 == "1";
                        //Vd_Salesperson_Division_K1K2.Checked = spm_Sales_1.Divison_K1K2 == "1";
                    }
                    #endregion

                    #region 审批项初始化
                    switch (TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                        case "CA Check":
                        case "CA Confirm":
                        case "CCC":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;

                        case "RSM/RPM":
                            Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                    }
                    #endregion
                }
                #endregion

                #region 设置控件禁启用
                bool flg11 = ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit) ? true : false;
                SetEnable(TaskAPI.IsInitiate && TaskAPI.IsAllowSubmit, DrpPriority);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(false, P_VK1K2);
                SetVisible(flg11, Add_K1, Add_K2, Add_K3, Delete_K1, Delete_K2, Delete_K3);
                bool flg12 = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;
                SetEnable(flg12, VD_K1, VD_K2, VD_K3, Vd_Ka, Vd_Kc, Vd_Kd, Vd_Ke, Vd_Kf, Vd_Kg, Vd_Kh, Vd_Kha, Vd_Ki);
                SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                SetEnable(false, Vd_Salesperson_Division_K1, Vd_Salesperson_Division_K2, Vd_Salesperson_Division_K3);
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);
                Attachment1.AllowDelete = flg11;
                Attachment1.AllowUpload = flg11;
                InitTabs();
                #endregion
            }
        }


        //protected override void OnLoad(EventArgs e)
        //{
        //    InitControls();
        //    base.OnLoad(e);
        //}

        public void InitControls()
        {

            gv_Sales_K1.Key = Key;
            #region 发起步骤
            if (TaskAPI.IsInitiate)
            {
                List<mdc_spm_Sales_Gv_1> sales_1_s = new List<mdc_spm_Sales_Gv_1>();
                for (int i = 0; i < 5; i++)
                {
                    sales_1_s.Add(new mdc_spm_Sales_Gv_1());
                    //sales_1_s[i].ID = (i + 1).ToString();
                }
                gv_Sales_K1.DataSource = sales_1_s;
            }
            #endregion

            #region 审批环节
            else
            {
                IList<mdc_spm_Sales_Gv_1> sales_1_s = (mdc_spm_Sales_Gv_1.process == TaskAPI.Process & mdc_spm_Sales_Gv_1.incident == TaskAPI.Incident).List<mdc_spm_Sales_Gv_1>();
                if (sales_1_s.Count == 0)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        sales_1_s.Add(new mdc_spm_Sales_Gv_1());
                        //sales_1_s[i].ID = (i + 1).ToString();
                    }
                }
                gv_Sales_K1.DataSource = sales_1_s;

            }
            #endregion
            gv_Sales_K2.Key = Key;
            #region 发起步骤
            if (TaskAPI.IsInitiate)
            {
                List<mdc_spm_Sales_Gv_2> sales_1_s = new List<mdc_spm_Sales_Gv_2>();
                for (int i = 0; i < 5; i++)
                {
                    sales_1_s.Add(new mdc_spm_Sales_Gv_2());
                    //sales_1_s[i].ID = (i + 1).ToString();
                }
                gv_Sales_K2.DataSource = sales_1_s;
            }
            #endregion

            #region 审批环节
            else
            {
                IList<mdc_spm_Sales_Gv_2> sales_1_s = (mdc_spm_Sales_Gv_2.process == TaskAPI.Process & mdc_spm_Sales_Gv_2.incident == TaskAPI.Incident).List<mdc_spm_Sales_Gv_2>();
                if (sales_1_s.Count == 0)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        sales_1_s.Add(new mdc_spm_Sales_Gv_2());
                        //sales_1_s[i].ID = (i + 1).ToString();
                    }
                }
                gv_Sales_K2.DataSource = sales_1_s;

            }
            #endregion
            gv_Sales_K3.Key = Key;
            #region 发起步骤
            if (TaskAPI.IsInitiate)
            {
                List<mdc_spm_Sales_Gv_3> sales_1_s = new List<mdc_spm_Sales_Gv_3>();
                for (int i = 0; i < 5; i++)
                {
                    sales_1_s.Add(new mdc_spm_Sales_Gv_3());
                    //sales_1_s[i].ID = (i + 1).ToString();
                }
                gv_Sales_K3.DataSource = sales_1_s;
            }
            #endregion

            #region 审批环节
            else
            {
                IList<mdc_spm_Sales_Gv_3> sales_1_s = (mdc_spm_Sales_Gv_3.process == TaskAPI.Process & mdc_spm_Sales_Gv_3.incident == TaskAPI.Incident).List<mdc_spm_Sales_Gv_3>();
                if (sales_1_s.Count == 0)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        sales_1_s.Add(new mdc_spm_Sales_Gv_3());
                        //sales_1_s[i].ID = (i + 1).ToString();
                    }
                }
                gv_Sales_K3.DataSource = sales_1_s;

            }
            #endregion
            gv_Sales_K1K2.Key = Key;
            #region 发起步骤
            if (TaskAPI.IsInitiate)
            {
                List<mdc_spm_Sales_Gv_4> sales_1_s = new List<mdc_spm_Sales_Gv_4>();
                for (int i = 0; i < 10; i++)
                {
                    sales_1_s.Add(new mdc_spm_Sales_Gv_4());
                    //sales_1_s[i].ID = (i + 1).ToString();
                }
                gv_Sales_K1K2.DataSource = sales_1_s;
            }
            #endregion

            #region 审批环节
            else
            {
                IList<mdc_spm_Sales_Gv_4> sales_1_s = (mdc_spm_Sales_Gv_4.process == TaskAPI.Process & mdc_spm_Sales_Gv_4.incident == TaskAPI.Incident).List<mdc_spm_Sales_Gv_4>();
                if (sales_1_s.Count == 0)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        sales_1_s.Add(new mdc_spm_Sales_Gv_4());
                        //sales_1_s[i].ID = (i + 1).ToString();
                    }
                }
                gv_Sales_K1K2.DataSource = sales_1_s;

            }
            #endregion
            //SetVisible(flg, SEFI_1_Add, SEFI_2_Add);
        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                bool flag2 = false;
                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if ((TaskAPI.IsInitiate) && TaskAPI.IsAllowSubmit)
                    {
                        ApplicationNo.Text = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName = UserAPI.UserName;
                        TaskAPI["ApplicationNo"] = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"] = UserAPI.UserName;
                        TaskAPI["Time"] = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"] = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }

                    TaskAPI.Summary = (VD_Category.SelectedItem.Text.Split(',').Length >= 2 ? VD_Category.SelectedItem.Text.Split(',')[1].Trim() : VD_Category.Text)
                                    + " / " + ApplicationNo.Text;//+ (VD.Checked ? " / Vendor " : "") + (SA.Checked ? " / Employee " : "");

                    TaskAPI["Actions"] = VD_Category.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;

                    #region 判断return 流程走向是否改变
                    string vd_k1 = "0";
                    string vd_ki = "0";
                    string vd_k2 = "0";
                    mdc_spm_Sales_2 spm_Sales_1 = (mdc_spm_Sales_2.process == TaskAPI.Process & mdc_spm_Sales_2.incident == TaskAPI.Incident).ListFirst<mdc_spm_Sales_2>();
                    if (spm_Sales_1 != null)
                    {
                        if (VD_Region.SelectedValue == spm_Sales_1.Sales_Region && VD_Sales_Office.SelectedValue == spm_Sales_1.Sales_Office_1)
                        {
                            if (Vd_Salesperson_Division_K1.Checked)
                            {
                                vd_k1 = "1";
                            }
                            if (Vd_Salesperson_Division_K3.Checked)
                            {
                                vd_k1 = "1";
                            }
                            if (spm_Sales_1.KI == "1")
                            {
                                vd_k2 = "1";
                                vd_k1 = "1";
                            }
                            if (spm_Sales_1.Divison_K2 == "1")
                            {
                                vd_k2 = "1";
                            }
                            if (Vd_Salesperson_Division_K2.Checked && Vd_Ki.Checked)
                            {
                                vd_k1 = "1";
                                vd_ki = "1";
                            }
                            if (Vd_Salesperson_Division_K2.Checked && !Vd_Ki.Checked)
                            {
                                vd_k2 = "1";
                                vd_ki = "0";
                            }
                            if (vd_k2 == spm_Sales_1.Divison_K2 && (vd_k1 == spm_Sales_1.Divison_K1 || vd_k1 == spm_Sales_1.Divison_K3 || vd_ki == spm_Sales_1.KI))
                            {
                                flag2 = true;
                            }
                        }

                    }
                    #endregion 引擎传值
                    #region 从数据库取得流程步骤处理人
                    if (TaskAPI.IsBeginStep)
                    {
                        SortedList<string, string> rec_a = new SortedList<string, string>();

                        IList<mdc_spm_Recipient> rec_s = (mdc_spm_Recipient.process == TaskAPI.Process & mdc_spm_Recipient.status == 1
                                                             & mdc_spm_Recipient.step.In(new string[4] { "DMO Approve", "DMO Maintain", "DMO Check", "CCC" })).List<mdc_spm_Recipient>();
                        foreach (mdc_spm_Recipient rec in rec_s)
                        {
                            if (!rec_a.ContainsKey(rec.Step))
                            {
                                rec_a.Add(rec.Step, rec.Recipient);
                                continue;
                            }

                            if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                            {
                                continue;
                            }

                            rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                        }

                        //步骤处理人赋值
                        for (int i = 0; i < rec_a.Keys.Count; i++)
                        {
                            TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        }
                    }
                }
                    #endregion
                #region RSM/RPM
                if (TaskAPI.IsBeginStep)
                {
                    string division = "";
                    string salesGroup = "";
                    if (Vd_Salesperson_Division_K1.Checked)
                    {
                        division = "K1";
                        //salesGroup = "KA";
                    }
                    if (Vd_Salesperson_Division_K3.Checked && !Vd_Salesperson_Division_K1.Checked)
                    {
                        division = "K3";
                        //salesGroup = "KA";
                    }
                    if (Vd_Salesperson_Division_K2.Checked && Vd_Ki.Checked)
                    {
                        division = "K1";
                        //salesGroup = "KA";
                    }
                    if (Vd_Salesperson_Division_K2.Checked && !Vd_Ki.Checked)
                    {
                        division = "K2";
                        //salesGroup = "KG";
                    }
                    if (Vd_Kc.Checked)
                    {
                        division = "K9";
                    }
                    List<string> cmd_tar = new List<string>();
                    List<string> cmd_tar3 = new List<string>();
                    string region = VD_Region.SelectedValue.Length >= 3 ? VD_Region.SelectedValue.Substring(0, 3) : VD_Region.SelectedValue;

                    IList<mdc_spm_Recipient> cmd_src = (mdc_spm_Recipient.process == TaskAPI.Process & mdc_spm_Recipient.step.In(new string[2] { "RSM/RPM", "CA Check" })
                                                  & mdc_spm_Recipient.salesOffice == (VD_Sales_Office.Text.Length > 3 ? VD_Sales_Office.SelectedValue.Substring(0, 4) : VD_Sales_Office.Text) & mdc_spm_Recipient.division == division).List<mdc_spm_Recipient>();

                    foreach (mdc_spm_Recipient cmd_r in cmd_src)
                    {
                        if (!cmd_tar3.Contains(cmd_r.Recipient) && cmd_r.Step.ToUpper() == "CA CHECK" & (cmd_r.Region == region || cmd_r.Region == "*"))
                        {
                            if (cmd_r.Recipient == "#N/A") continue;
                            cmd_tar3.Add(cmd_r.Recipient);
                            continue;
                        }

                        if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "RSM/RPM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                        {
                            if (cmd_r.Recipient == "#N/A") continue;
                            cmd_tar.Add(cmd_r.Recipient);
                            continue;
                        }

                    }

                    //if (TaskAPI["R_RSM_RPM"] != null)
                    //{
                    //    object[] obj1 = (object[])(TaskAPI["R_RSM_RPM"]);
                    //    for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                    //    {
                    //        obj1[i] = null;
                    //    }
                    //    TaskAPI["R_RSM_RPM"] = obj1;
                    //}
                    //if (TaskAPI["R_CA_Check"] != null)
                    //{
                    //    object[] obj2 = (object[])(TaskAPI["R_CA_Check"]);
                    //    for (int i = 0; i <= obj2.GetUpperBound(0); i++)
                    //    {
                    //        obj2[i] = null;
                    //    }
                    //    TaskAPI["R_CA_Check"] = obj2;
                    //}
                    bool falg_dt = false;
                    TaskDB db = new TaskDB();
                    db.Storage("bpmDB");
                    DataTable dt = db.Query(" select steplabel from  TASKS where processname='" + TaskAPI.Process + "' and  Incident=" + TaskAPI.Incident + " ");
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i][0].ToString() == "S")
                            {
                                falg_dt = true;
                                break;
                            }
                        }
                    }
                    if (!falg_dt)
                    {
                        TaskAPI["R_RSM_RPM"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                        TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();
                    }
                }


                #endregion
                if (!TaskAPI.IsBeginStep)
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"] = TaskAPI.TaskID;
                }


                #endregion

                #region 提交步骤
                bool flg = false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check")
                    {
                        mdc_spm_Sales_2 spm_Sales_1 = new mdc_spm_Sales_2();

                        if ((mdc_spm_Sales_2.process == TaskAPI.Process & mdc_spm_Sales_2.incident == TaskAPI.Incident).Count<mdc_spm_Sales_2>() > 0)
                        {
                            spm_Sales_1 = (mdc_spm_Sales_2.process == TaskAPI.Process & mdc_spm_Sales_2.incident == TaskAPI.Incident).ListFirst<mdc_spm_Sales_2>();

                        }
                        else
                        {
                            spm_Sales_1.Process = TaskAPI.Process;
                            spm_Sales_1.Incident = TaskAPI.Incident;
                            spm_Sales_1.UserName = UserAPI.UserName;
                            //spm_Sales_1.UserFullName = UserAPI.UserFullName;
                            spm_Sales_1.ApplicationNo = ApplicationNo.Text;
                            spm_Sales_1.Time = System.DateTime.Now;
                            spm_Sales_1.Status = 0;
                            spm_Sales_1.Department = UserAPI.Department;
                        }

                        spm_Sales_1.Type = VD_Category.SelectedValue;
                        spm_Sales_1.DrpPriority = DrpPriority.SelectedValue;
                        spm_Sales_1.Sales_Office_1 = VD_Sales_Office.SelectedItem.Text;
                        spm_Sales_1.Sales_Region = VD_Region.SelectedItem.Text;
                        spm_Sales_1.KA = Vd_Ka.Checked ? "1" : "0";
                        spm_Sales_1.KC = Vd_Kc.Checked ? "1" : "0";
                        spm_Sales_1.KD = Vd_Kd.Checked ? "1" : "0";
                        spm_Sales_1.KI = Vd_Ki.Checked ? "1" : "0";
                        spm_Sales_1.KG = Vd_Kg.Checked ? "1" : "0";
                        spm_Sales_1.KH = Vd_Kh.Checked ? "1" : "0";
                        spm_Sales_1.KHA = Vd_Kha.Checked ? "1" : "0";
                        spm_Sales_1.KE = Vd_Ke.Checked ? "1" : "0";
                        spm_Sales_1.KF = Vd_Kf.Checked ? "1" : "0";

                        spm_Sales_1.Divison_K1 = Vd_Salesperson_Division_K1.Checked ? "1" : "0";
                        spm_Sales_1.Divison_K2 = Vd_Salesperson_Division_K2.Checked ? "1" : "0";
                        spm_Sales_1.Divison_K3 = Vd_Salesperson_Division_K3.Checked ? "1" : "0";
                        //spm_Sales_1.Divison_K1K2 = Vd_Salesperson_Division_K1K2.Checked ? "1" : "0";

                        //spm_Sales_1.Actions = VD_Category.SelectedItem.Text;
                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, spm_Sales_1);
                    }
                    #endregion

                    Save();

                    #region Priority功能
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }
                    #endregion

                    #region “DMO Maintain”步骤
                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {

                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (mdc_spm_Sales_2.process == TaskAPI.Process & mdc_spm_Sales_2.incident == TaskAPI.Incident).Edit<mdc_spm_Sales_2>(p =>
                        {
                            // p.SAP_Code = SAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;

                        }
                        );
                    }
                    #endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见
                    #region 退回步骤并返回功能 传值
                    if (TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")] != null)
                    {
                        object[] obj = (object[])(TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")]);
                        for (int i = 0; i <= obj.GetUpperBound(0); i++)
                        {
                            obj[i] = null;
                        }
                        obj[0] = UserAPI.UserName;
                        TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")] = obj;
                    }
                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();
                    #endregion
                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {

                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }
                    (mdc_spm_Sales_Gv_1.process == TaskAPI.Process & mdc_spm_Sales_Gv_1.incident == 0 & mdc_spm_Sales_Gv_1.userName == UserAPI.UserName).Edit<mdc_spm_Sales_Gv_1>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                    (mdc_spm_Sales_Gv_2.process == TaskAPI.Process & mdc_spm_Sales_Gv_2.incident == 0 & mdc_spm_Sales_Gv_2.userName == UserAPI.UserName).Edit<mdc_spm_Sales_Gv_2>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                    (mdc_spm_Sales_Gv_3.process == TaskAPI.Process & mdc_spm_Sales_Gv_3.incident == 0 & mdc_spm_Sales_Gv_3.userName == UserAPI.UserName).Edit<mdc_spm_Sales_Gv_3>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                    (mdc_spm_Sales_Gv_4.process == TaskAPI.Process & mdc_spm_Sales_Gv_4.incident == 0 & mdc_spm_Sales_Gv_4.userName == UserAPI.UserName).Edit<mdc_spm_Sales_Gv_4>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.userName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (mdc_spm_Sales_2.process == TaskAPI.Process & mdc_spm_Sales_2.incident == 0 & mdc_spm_Sales_2.userName == UserAPI.UserName).Edit<mdc_spm_Sales_2>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });


                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }

        }
        #endregion
        #region 事件 Add(增加行)
        protected void Add_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).ID)
            {
                case "Add_K1":
                    List<mdc_spm_Sales_Gv_1> sefi_1_s = (List<mdc_spm_Sales_Gv_1>)this.gv_Sales_K1.DataSource;
                    mdc_spm_Sales_Gv_1 sefi_1 = new mdc_spm_Sales_Gv_1();
                    //sefi_1.ID = sefi_1_s.Count + 1;
                    sefi_1_s.Insert(sefi_1_s.Count, sefi_1);
                    gv_Sales_K1.DataSource = sefi_1_s;
                    gv_Sales_K1.DataBind();
                    break;
                case "Add_K2":
                    List<mdc_spm_Sales_Gv_2> sefi_2_s = (List<mdc_spm_Sales_Gv_2>)this.gv_Sales_K2.DataSource;
                    mdc_spm_Sales_Gv_2 sefi_2 = new mdc_spm_Sales_Gv_2();
                    //sefi_1.ID = sefi_1_s.Count + 1;
                    sefi_2_s.Insert(sefi_2_s.Count, sefi_2);
                    gv_Sales_K2.DataSource = sefi_2_s;
                    gv_Sales_K2.DataBind();
                    break;
                case "Add_K3":
                    List<mdc_spm_Sales_Gv_3> sefi_3_s = (List<mdc_spm_Sales_Gv_3>)this.gv_Sales_K3.DataSource;
                    mdc_spm_Sales_Gv_3 sefi_3 = new mdc_spm_Sales_Gv_3();
                    //sefi_1.ID = sefi_1_s.Count + 1;
                    sefi_3_s.Insert(sefi_3_s.Count, sefi_3);
                    gv_Sales_K3.DataSource = sefi_3_s;
                    gv_Sales_K3.DataBind();
                    break;
            }


        }
        #endregion
        #region 事件 Delete(删除行)
        protected void Delete_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).ID)
            {
                case "Delete_K1":
                    List<mdc_spm_Sales_Gv_1> base_1_s = (List<mdc_spm_Sales_Gv_1>)gv_Sales_K1.DataSource;
                    IList<mdc_spm_Sales_Gv_1> base1 = (mdc_spm_Sales_Gv_1.process == TaskAPI.Process & mdc_spm_Sales_Gv_1.incident == TaskAPI.Incident).List<mdc_spm_Sales_Gv_1>();
                    if (base_1_s.Count == 1)
                    {
                        Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留最后一个 Sheet ！',false)");
                        return;
                    }
                    base_1_s.RemoveAt(gv_Sales_K1.ChangedRowIndex == -1 || gv_Sales_K1.ChangedRowIndex >= base_1_s.Count ? base_1_s.Count - 1 : gv_Sales_K1.ChangedRowIndex);
                    bool flag = false;
                    foreach (mdc_spm_Sales_Gv_1 base_1 in base1)
                    {

                        foreach (mdc_spm_Sales_Gv_1 base_2 in base_1_s)
                        {
                            if (base_2.ID == base_1.ID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            Storage.Delete(base_1);
                        }
                        flag = false;
                    }
                    gv_Sales_K1.DataSource = base_1_s;
                    gv_Sales_K1.DataBind();
                    break;
                case "Delete_K2":
                    List<mdc_spm_Sales_Gv_2> base_2_s = (List<mdc_spm_Sales_Gv_2>)gv_Sales_K2.DataSource;
                    IList<mdc_spm_Sales_Gv_2> base2 = (mdc_spm_Sales_Gv_2.process == TaskAPI.Process & mdc_spm_Sales_Gv_2.incident == TaskAPI.Incident).List<mdc_spm_Sales_Gv_2>();
                    if (base_2_s.Count == 1)
                    {
                        Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留最后一个 Sheet ！',false)");
                        return;
                    }
                    base_2_s.RemoveAt(gv_Sales_K2.ChangedRowIndex == -1 || gv_Sales_K2.ChangedRowIndex >= base_2_s.Count ? base_2_s.Count - 1 : gv_Sales_K2.ChangedRowIndex);
                    bool flag2 = false;
                    foreach (mdc_spm_Sales_Gv_2 base_2 in base2)
                    {

                        foreach (mdc_spm_Sales_Gv_2 base_1 in base_2_s)
                        {
                            if (base_2.ID == base_1.ID)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                        if (!flag2)
                        {
                            Storage.Delete(base_2);
                        }
                        flag2 = false;
                    }
                    gv_Sales_K2.DataSource = base_2_s;
                    gv_Sales_K2.DataBind();
                    break;
                case "Delete_K3":
                    List<mdc_spm_Sales_Gv_3> base_3_s = (List<mdc_spm_Sales_Gv_3>)gv_Sales_K3.DataSource;
                    IList<mdc_spm_Sales_Gv_3> base3 = (mdc_spm_Sales_Gv_3.process == TaskAPI.Process & mdc_spm_Sales_Gv_3.incident == TaskAPI.Incident).List<mdc_spm_Sales_Gv_3>();
                    if (base_3_s.Count == 1)
                    {
                        Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留最后一个 Sheet ！',false)");
                        return;
                    }
                    base_3_s.RemoveAt(gv_Sales_K3.ChangedRowIndex == -1 || gv_Sales_K3.ChangedRowIndex >= base_3_s.Count ? base_3_s.Count - 1 : gv_Sales_K3.ChangedRowIndex);
                    bool flag3 = false;
                    foreach (mdc_spm_Sales_Gv_3 base_1 in base3)
                    {

                        foreach (mdc_spm_Sales_Gv_3 base_2 in base_3_s)
                        {
                            if (base_2.ID == base_1.ID)
                            {
                                flag3 = true;
                                break;
                            }
                        }
                        if (!flag3)
                        {
                            Storage.Delete(base_1);
                        }
                        flag3 = false;
                    }
                    gv_Sales_K3.DataSource = base_3_s;
                    gv_Sales_K3.DataBind();
                    break;

            }
        }
        #endregion
        #region 事件 CheckedChanged
        protected void VD_CheckedChanged(object sender, EventArgs e)
        {

        }
        #endregion

        #region 事件 Category变换
        protected void VD_Category_SelectedIndexChanged(object sender, EventArgs e)
        {
            //SetEnable((VD_Category.SelectedValue == "1" || VD_Category.SelectedValue == "2" || VD_Category.SelectedValue == "3" || VD_Category.SelectedValue == "4"));

        }
        #endregion
        #region 事件 Sales_Office变换
        protected void VD_Sales_Office_SelectedIndexChanged(object sender, EventArgs e)
        {
            VD_Region.Items.Clear();
            VD_Region.Items.Add(new ListItem("", ""));
            IList<m_Sales_Office> brs = (m_Sales_Office.status == 1 & (m_Sales_Office.sales_Office == VD_Sales_Office.SelectedValue
             | m_Sales_Office.sales_Office == "")).List<m_Sales_Office>();
            foreach (m_Sales_Office BR in brs)
            {
                if (!string.IsNullOrEmpty(VD_Sales_Office.SelectedItem.Text.ToString().Trim()))
                {
                    if (VD_Region.Items.FindByValue(BR.Region_Code_Name.Substring(3, BR.Region_Code_Name.Length - 3)) == null)
                    {
                        VD_Region.Items.Add(new ListItem(BR.Region_Code_Name.Substring(3, BR.Region_Code_Name.Length - 3), BR.Region_Code_Name.Substring(3, BR.Region_Code_Name.Length - 3)));
                    }
                }

            }
            if (brs.Count == 0)
            {
                InitDropDownList();
            }
        }
        #endregion
        #region 事件 VD_Region变换
        protected void VD_Region_SelectedIndexChanged(object sender, EventArgs e)
        {
            //IList<m_Region_SalesOffice> brs = (m_Region_SalesOffice.status == 1 & (m_Region_SalesOffice.region.ToString() == VD_Region.SelectedValue
            //    | m_Region_SalesOffice.region.ToString() == "")).List<m_Region_SalesOffice>();      
            //foreach (m_Region_SalesOffice BR in brs)
            //{
            //    if (VD_Sales_Office.Items.FindByValue(BR.SalesOffice) == null)
            //    {
            //        VD_Sales_Office.Items.Add(new ListItem(BR.SalesOffice, BR.SalesOffice));
            //    }
            //    else
            //    {
            //        int i = 0;
            //        foreach (ListItem item in VD_Sales_Office.Items)
            //        {
            //            if (item.Text.Trim() == BR.SalesOffice)
            //            {
            //                VD_Sales_Office.SelectedIndex = i;
            //                break;
            //            }
            //            i++;
            //        }
            //    }
            //}
            //if (brs.Count == 0)
            //{
            //    InitDropDownList();
            //}
        }
        #endregion
        #region 事件 Tabs切换
        protected void Tabs_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P_VK1, P_VK1K2, P_VK2, P_VK3);
            VD_K1.CssClass = "tabs1";
            VD_K2.CssClass = "tabs1";
            VD_K3.CssClass = "tabs1";
            VD_K1K2.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "VD_K1":
                    VD_K1.CssClass = "tabs2";
                    P_VK1.Visible = true;
                    break;
                case "VD_K2":
                    VD_K2.CssClass = "tabs2";
                    P_VK2.Visible = true;
                    break;
                case "VD_K3":
                    VD_K3.CssClass = "tabs2";
                    P_VK3.Visible = true;
                    break;
                case "VD_K1K2":
                    VD_K1K2.CssClass = "tabs2";
                    P_VK1K2.Visible = true;
                    break;
            }
            #endregion
        }
        #endregion

        #region 方法 初始化Tabs
        protected void InitTabs()
        {
            VD_K1.Visible = this.Vd_Salesperson_Division_K1.Checked;
            VD_K2.Visible = Vd_Salesperson_Division_K2.Checked;
            VD_K3.Visible = Vd_Salesperson_Division_K3.Checked;
            //VD_K1K2.Visible = Vd_Salesperson_Division_K1K2.Checked;
            if (
                (VD_K2.CssClass == "tabs2" && Vd_Salesperson_Division_K2.Checked)
             || (VD_K3.CssClass == "tabs2" && Vd_Salesperson_Division_K3.Checked)
             )
            {
                return;
            }

            SetVisible(false, P_VK1, P_VK2, P_VK3);
            VD_K1.CssClass = "tabs1";
            VD_K2.CssClass = "tabs1";
            VD_K3.CssClass = "tabs1";
            //VD_K1K2.CssClass = "tabs1";

            //默认第1个显示 Tabs被选中
            if (VD_K1.Visible)
            {
                VD_K1.CssClass = "tabs2";
                P_VK1.Visible = true;
                //return;
            }

            if (VD_K2.Visible)
            {
                VD_K2.CssClass = "tabs2";
                P_VK2.Visible = true;
                //return;
            }

            if (VD_K3.Visible)
            {
                VD_K3.CssClass = "tabs2";
                P_VK3.Visible = true;
                //return;
            }
            //if (VD_K1K2.Visible)
            //{
            //    VD_K1K2.CssClass = "tabs2";
            //    P_VK1K2.Visible = true;
            //    //return;
            //}
        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                #region Sales Office(Sold to)
                VD_Sales_Office.Items.Clear();
                VD_Sales_Office.Items.Add(new ListItem("", ""));
                IList<m_Sales_Office1> bsos = (m_Sales_Office1.status == 1).List<m_Sales_Office1>();
                foreach (m_Sales_Office1 BSO in bsos)
                {
                    VD_Sales_Office.Items.Add(new ListItem(BSO.Sales_Office1, BSO.Sales_Office1));
                }
                #endregion
                #region VD_Region()
                VD_Region.Items.Clear();
                VD_Region.Items.Add(new ListItem("", ""));
                IList<m_Region_SalesOffice> m_rs = (m_Region_SalesOffice.status == 1).List<m_Region_SalesOffice>();
                foreach (m_Region_SalesOffice RS in m_rs)
                {
                    VD_Region.Items.Add(new ListItem(RS.Region.ToString().Substring(3, RS.Region.Length - 3), RS.Region.ToString().Substring(3, RS.Region.Length - 3)));
                }
                #endregion

                //IsLoaded = true;
            }
        }
        #endregion

        #region 方法 Save(保存数据库)
        public void Save()
        {
            //if (!Status.IsEdited)
            //{
            //    return;
            //}
            foreach (mdc_spm_Sales_Gv_1 sales_1 in (List<mdc_spm_Sales_Gv_1>)gv_Sales_K1.DataSource)
            {
                if (VD_Category.SelectedValue == "2")
                {
                    if (string.IsNullOrEmpty(sales_1.New_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "3")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "1")
                {
                    if (string.IsNullOrEmpty(sales_1.Sap_Code) || string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.New_Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "4")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code))
                    {
                        continue;
                    }
                }
                if (TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check")
                {
                    sales_1.Process = TaskAPI.Process;
                    sales_1.Incident = TaskAPI.Incident;
                    sales_1.UserName = UserAPI.UserName;
                }
                sales_1.Time = System.DateTime.Now;
                sales_1.Status = 1;
                Storage.Save(sales_1);
            }
            foreach (mdc_spm_Sales_Gv_2 sales_1 in (List<mdc_spm_Sales_Gv_2>)gv_Sales_K2.DataSource)
            {
                if (VD_Category.SelectedValue == "2")
                {
                    if (string.IsNullOrEmpty(sales_1.New_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "3")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "1")
                {
                    if (string.IsNullOrEmpty(sales_1.Sap_Code) || string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.New_Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "4")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code))
                    {
                        continue;
                    }
                }
                if (TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check")
                {
                    sales_1.Process = TaskAPI.Process;
                    sales_1.Incident = TaskAPI.Incident;
                    sales_1.UserName = UserAPI.UserName;
                }
                sales_1.Time = System.DateTime.Now;
                sales_1.Status = 1;
                Storage.Save(sales_1);
            }
            foreach (mdc_spm_Sales_Gv_3 sales_1 in (List<mdc_spm_Sales_Gv_3>)gv_Sales_K3.DataSource)
            {
                if (VD_Category.SelectedValue == "2")
                {
                    if (string.IsNullOrEmpty(sales_1.New_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "3")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "1")
                {
                    if (string.IsNullOrEmpty(sales_1.Sap_Code) || string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.New_Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "4")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code))
                    {
                        continue;
                    }
                }
                if (TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check")
                {
                    sales_1.Process = TaskAPI.Process;
                    sales_1.Incident = TaskAPI.Incident;
                    sales_1.UserName = UserAPI.UserName;
                }
                sales_1.Time = System.DateTime.Now;
                sales_1.Status = 1;
                Storage.Save(sales_1);
            }
            foreach (mdc_spm_Sales_Gv_4 sales_1 in (List<mdc_spm_Sales_Gv_4>)gv_Sales_K1K2.DataSource)
            {
                if (VD_Category.SelectedValue == "2")
                {
                    if (string.IsNullOrEmpty(sales_1.New_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "3")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "1")
                {
                    if (string.IsNullOrEmpty(sales_1.Sap_Code) || string.IsNullOrEmpty(sales_1.Old_Sap_Code) || string.IsNullOrEmpty(sales_1.New_Sap_Code))
                    {
                        continue;
                    }

                }
                else if (VD_Category.SelectedValue == "4")
                {
                    if (string.IsNullOrEmpty(sales_1.Old_Sap_Code))
                    {
                        continue;
                    }
                }
                if (TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check")
                {
                    sales_1.Process = TaskAPI.Process;
                    sales_1.Incident = TaskAPI.Incident;
                    sales_1.UserName = UserAPI.UserName;
                }
                sales_1.Time = System.DateTime.Now;
                sales_1.Status = 1;
                Storage.Save(sales_1);
            }
        }
        //TaskAPI["Material"] = SEFI_Material;

        #endregion


        #region 方法 gv_Sales_K1 数据取得
        protected void gv_Sales_1_DataBinding(object sender, EventArgs e)
        {
            //if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit && gv_CCC_1.ChangedColumnIndex == 9)
            //if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit && (gv_Sales_1.ChangedColumnIndex == 0 || gv_Sales_1.ChangedColumnIndex == 1))
            H2.NET.Controls.GridView gv = (H2.NET.Controls.GridView)sender;
            string id = gv.ID.ToString();
            if (id == "gv_Sales_K1")
            {
                List<mdc_spm_Sales_Gv_1> ccc_s = gv_Sales_K1.DataSource as List<mdc_spm_Sales_Gv_1>;
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 0)
                {
                    foreach (mdc_spm_Sales_Gv_1 ccc in ccc_s)
                    {
                        m_Customer ncc = (m_Customer.customerCode == ccc.Sap_Code).ListFirst<m_Customer>();
                        if (ncc != null)
                        {
                            ccc.Sold_CN_Name = ncc.CustomerName;
                        }
                        else
                        {
                            ccc.Sold_CN_Name = "";
                        }
                    }
                }
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 2)
                {
                    foreach (mdc_spm_Sales_Gv_1 ccc in ccc_s)
                    {
                        m_Employee_Code ncc = (m_Employee_Code.persNo == ccc.Old_Sap_Code).ListFirst<m_Employee_Code>();
                        if (ncc != null)
                        {
                            ccc.Old_CN_Name = ncc.Employee;
                            ccc.Vendor_Code = ncc.Vendor_Code;
                        }
                        else
                        {
                            ccc.Vendor_Code = "";
                            ccc.Old_CN_Name = "";
                        }
                    }
                }
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 4)
                {
                    foreach (mdc_spm_Sales_Gv_1 ccc in ccc_s)
                    {
                        m_Employee_Code ncc1 = (m_Employee_Code.persNo == ccc.New_Sap_Code).ListFirst<m_Employee_Code>();
                        if (ncc1 != null)
                        {
                            ccc.New_CN_Name = ncc1.Employee;
                        }
                        else
                        {
                            ccc.New_CN_Name = "";
                        }
                    }
                }
            }
            if (id == "gv_Sales_K2")
            {
                List<mdc_spm_Sales_Gv_2> ccc_s = gv_Sales_K2.DataSource as List<mdc_spm_Sales_Gv_2>;
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 0)
                {
                    foreach (mdc_spm_Sales_Gv_2 ccc in ccc_s)
                    {
                        m_Customer ncc = (m_Customer.customerCode == ccc.Sap_Code).ListFirst<m_Customer>();
                        if (ncc != null)
                        {
                            ccc.Sold_CN_Name = ncc.CustomerName;
                        }
                        else
                        {
                            ccc.Sold_CN_Name = "";
                        }
                    }
                }
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 2)
                {
                    foreach (mdc_spm_Sales_Gv_2 ccc in ccc_s)
                    {
                        m_Employee_Code ncc = (m_Employee_Code.persNo == ccc.Old_Sap_Code).ListFirst<m_Employee_Code>();
                        if (ncc != null)
                        {
                            ccc.Old_CN_Name = ncc.Employee;
                            ccc.Vendor_Code = ncc.Vendor_Code;
                        }
                        else
                        {
                            ccc.Vendor_Code = "";
                            ccc.Old_CN_Name = "";
                        }
                    }
                }
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 4)
                {
                    foreach (mdc_spm_Sales_Gv_2 ccc in ccc_s)
                    {
                        m_Employee_Code ncc1 = (m_Employee_Code.persNo == ccc.New_Sap_Code).ListFirst<m_Employee_Code>();
                        if (ncc1 != null)
                        {
                            ccc.New_CN_Name = ncc1.Employee;
                        }
                        else
                        {
                            ccc.New_CN_Name = "";
                        }
                    }
                }
            }
            if (id == "gv_Sales_K3")
            {
                List<mdc_spm_Sales_Gv_3> ccc_s = gv_Sales_K3.DataSource as List<mdc_spm_Sales_Gv_3>;
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 0)
                {
                    foreach (mdc_spm_Sales_Gv_3 ccc in ccc_s)
                    {
                        m_Customer ncc = (m_Customer.customerCode == ccc.Sap_Code).ListFirst<m_Customer>();
                        if (ncc != null)
                        {
                            ccc.Sold_CN_Name = ncc.CustomerName;
                        }
                        else
                        {
                            ccc.Sold_CN_Name = "";
                        }
                    }
                }
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 2)
                {
                    foreach (mdc_spm_Sales_Gv_3 ccc in ccc_s)
                    {
                        m_Employee_Code ncc = (m_Employee_Code.persNo == ccc.Old_Sap_Code).ListFirst<m_Employee_Code>();
                        if (ncc != null)
                        {
                            ccc.Old_CN_Name = ncc.Employee;
                            ccc.Vendor_Code = ncc.Vendor_Code;
                        }
                        else
                        {
                            ccc.Vendor_Code = "";
                            ccc.Old_CN_Name = "";
                        }
                    }
                }
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit && gv.ChangedColumnIndex == 4)
                {
                    foreach (mdc_spm_Sales_Gv_3 ccc in ccc_s)
                    {
                        m_Employee_Code ncc1 = (m_Employee_Code.persNo == ccc.New_Sap_Code).ListFirst<m_Employee_Code>();
                        if (ncc1 != null)
                        {
                            ccc.New_CN_Name = ncc1.Employee;
                        }
                        else
                        {
                            ccc.New_CN_Name = "";
                        }
                    }
                }
            }




        }
        #endregion
        #region 事件 CheckBox-必填
        protected void Vd_Salesperson_Division_K1_CheckedChanged(object sender, EventArgs e)
        {
            switch (((CheckBox)sender).ClientID)
            {
                case "Vd_Kc":

                    if (Vd_Ka.Checked || Vd_Kd.Checked || Vd_Kg.Checked || Vd_Kh.Checked || Vd_Kha.Checked || Vd_Ki.Checked || Vd_Ke.Checked || Vd_Kf.Checked)
                    {
                        Vd_Kc.Checked = false;
                    }
                    else
                    {
                        if (Vd_Kc.Checked)
                        {
                            Vd_Salesperson_Division_K1.Checked = true;
                            VD_K1.Visible = true;
                            P_VK1.Visible = true;
                            VD_K1.CssClass = "tabs2";
                            VD_K2.CssClass = "tabs1";
                            VD_K3.CssClass = "tabs1";
                            SetVisible(false, P_VK2, P_VK3);
                        }
                        else
                        {
                            VD_K1.Visible = false;
                            P_VK1.Visible = false;
                            Vd_Salesperson_Division_K1.Checked = false;
                        }
                    }
                    break;
                case "Vd_Ka":
                case "Vd_Kd":
                    if ((Vd_Ka.Checked || Vd_Kd.Checked) && (!Vd_Kg.Checked && !Vd_Kh.Checked && !Vd_Kha.Checked) && !Vd_Kc.Checked)
                    {
                        Vd_Salesperson_Division_K1.Checked = true;
                        VD_K1.Visible = true;
                        P_VK1.Visible = true;
                        VD_K1.CssClass = "tabs2";
                        VD_K2.CssClass = "tabs1";
                        VD_K3.CssClass = "tabs1";
                        SetVisible(false, P_VK2, P_VK3);
                    }
                    else
                    {
                        if (!Vd_Kc.Checked)
                        {
                            ((CheckBox)sender).Checked = false;
                            VD_K1.Visible = false;
                            P_VK1.Visible = false;
                            Vd_Salesperson_Division_K1.Checked = false;
                        }
                        else
                        {
                            ((CheckBox)sender).Checked = false;
                        }
                    }
                    break;
                case "Vd_Ki":
                    if (Vd_Ki.Checked && (!Vd_Kg.Checked && !Vd_Kh.Checked && !Vd_Kha.Checked) && !Vd_Kc.Checked)
                    {
                        Vd_Salesperson_Division_K2.Checked = true;
                        VD_K2.Visible = true;
                        P_VK2.Visible = true;
                        VD_K2.CssClass = "tabs2";
                        VD_K1.CssClass = "tabs1";
                        VD_K3.CssClass = "tabs1";
                        SetVisible(false, P_VK1, P_VK3);
                    }
                    else if (!Vd_Ki.Checked && !Vd_Kg.Checked && !Vd_Kh.Checked && !Vd_Kha.Checked && !Vd_Kc.Checked)
                    {
                        Vd_Salesperson_Division_K2.Checked = false;
                        VD_K2.Visible = false;
                        P_VK2.Visible = false;
                    }
                    else
                    {
                        ((CheckBox)sender).Checked = false;

                    }
                    break;
                case "Vd_Kg":
                case "Vd_Kh":
                case "Vd_Kha":
                    if (!Vd_Kc.Checked && (Vd_Kg.Checked || Vd_Kh.Checked || Vd_Kha.Checked) && (!Vd_Ki.Checked && !Vd_Salesperson_Division_K1.Checked && !Vd_Salesperson_Division_K3.Checked))
                    {
                        Vd_Salesperson_Division_K2.Checked = true;
                        VD_K2.Visible = true;
                        P_VK2.Visible = true;
                        VD_K2.CssClass = "tabs2";
                        VD_K3.CssClass = "tabs1";
                        VD_K1.CssClass = "tabs1";
                        SetVisible(false, P_VK1, P_VK3);
                    }
                    else if (!Vd_Kc.Checked && !Vd_Ki.Checked && !Vd_Kg.Checked && !Vd_Kh.Checked && !Vd_Kha.Checked)
                    {
                        Vd_Salesperson_Division_K2.Checked = false;
                        VD_K2.Visible = false;
                        P_VK2.Visible = false;
                    }
                    else
                    {
                        ((CheckBox)sender).Checked = false;
                    }
                    break;
                case "Vd_Ke":
                case "Vd_Kf":
                    if (!Vd_Kc.Checked && (Vd_Ke.Checked || Vd_Kf.Checked) && (!Vd_Kg.Checked && !Vd_Kh.Checked && !Vd_Kha.Checked))
                    {
                        Vd_Salesperson_Division_K3.Checked = true;
                        VD_K3.Visible = true;
                        P_VK3.Visible = true;
                        VD_K3.CssClass = "tabs2";
                        VD_K2.CssClass = "tabs1";
                        VD_K1.CssClass = "tabs1";
                        SetVisible(false, P_VK2, P_VK1);
                    }
                    else
                    {
                        ((CheckBox)sender).Checked = false;
                        Vd_Salesperson_Division_K3.Checked = false;
                        VD_K3.Visible = false;
                        P_VK3.Visible = false;
                    }
                    break;


            }

        }
        #endregion
        #region 方法 数据验证
        private List<string> DataValidation()
        {
            #region
            List<Regular> regs = new List<Regular>();

            regs.Add(new Regular(RegularExp.NotEmpty, VD_Category.SelectedItem.Text.ToString().Trim(), "&nbsp;&nbsp; 类型  Type 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, VD_Sales_Office.SelectedItem.Text.ToString().Trim(), "&nbsp;&nbsp; 区域 Sales_Office 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, VD_Region.SelectedItem.Text.ToString().Trim(), "&nbsp;&nbsp; 省份 Region 必填"));
            if (!Vd_Ka.Checked && !Vd_Kc.Checked && !Vd_Kd.Checked && !Vd_Ke.Checked && !Vd_Kf.Checked && !Vd_Kg.Checked && !Vd_Kh.Checked && !Vd_Kha.Checked && !Vd_Ki.Checked)
            {

                regs.Add(new Regular(RegularExp.NotEmpty, null, "&nbsp;&nbsp; Sales Group 必填"));
            }
            //regs.Add(new Regular(RegularExp.NotEmpty, VD_Sales_Division.SelectedItem.Text.ToString().Trim(), "&nbsp;&nbsp; 销售所属渠道  Sales_Division 必填"));
            int i = 1;
            foreach (mdc_spm_Sales_Gv_1 ccc in (List<mdc_spm_Sales_Gv_1>)this.gv_Sales_K1.DataSource)
            {
                if (string.IsNullOrEmpty(ccc.E_Mail) && string.IsNullOrEmpty(ccc.Tel) && string.IsNullOrEmpty(ccc.Sap_Code) && string.IsNullOrEmpty(ccc.Old_Sap_Code) && string.IsNullOrEmpty(ccc.New_Sap_Code))
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(ccc.E_Mail) || !string.IsNullOrEmpty(ccc.Tel))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 原销售人员编号必填"));
                }
                if (!string.IsNullOrEmpty(ccc.Tel))
                {
                    try
                    {
                        decimal length = Convert.ToDecimal(ccc.Tel.Length);
                        decimal len = Convert.ToDecimal(ccc.Tel);
                        if (length != 11)
                        {
                            regs.Add(new Regular(RegularExp.NotEmpty, (" ").Trim(), "&nbsp;&nbsp;K1 表单 行" + i + ": Tel： 手机号码为11数字！"));
                        }
                    }
                    catch (Exception)
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, (" ").Trim(), "&nbsp;&nbsp;K1 表单 行" + i + ": Tel： 手机号码为11数字！"));

                    }
                }
                if (VD_Category.SelectedValue == "2")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, (ccc.New_Sap_Code + "").Trim(), "&nbsp;&nbsp;K1 表单 行" + i + ": 新销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 客户编号为必填"));
                }
                else if (VD_Category.SelectedValue == "3")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 原销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 客户编号为必填"));
                }
                else if (VD_Category.SelectedValue == "1")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 客户编号为必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 原销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.New_Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 新销售人员编号必填"));

                }
                else if (VD_Category.SelectedValue == "4")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K1 表单 行" + i + ": 原销售人员或新销售人员编号必填"));

                }
                i++;
            }
            foreach (mdc_spm_Sales_Gv_2 ccc in (List<mdc_spm_Sales_Gv_2>)this.gv_Sales_K2.DataSource)
            {
                if (string.IsNullOrEmpty(ccc.E_Mail) && string.IsNullOrEmpty(ccc.Tel) && string.IsNullOrEmpty(ccc.Sap_Code) && string.IsNullOrEmpty(ccc.Old_Sap_Code) && string.IsNullOrEmpty(ccc.New_Sap_Code))
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(ccc.E_Mail) || !string.IsNullOrEmpty(ccc.Tel))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 原销售人员编号必填"));
                }
                if (!string.IsNullOrEmpty(ccc.Tel))
                {
                    try
                    {
                        decimal length = Convert.ToDecimal(ccc.Tel.Length);
                        decimal len = Convert.ToDecimal(ccc.Tel);
                        if (length != 11)
                        {
                            regs.Add(new Regular(RegularExp.NotEmpty, (" ").Trim(), "&nbsp;&nbsp;K2 表单 行" + i + ": Tel： 手机号码为11数字！"));
                        }
                    }
                    catch (Exception)
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, (" ").Trim(), "&nbsp;&nbsp;K2 表单 行" + i + ": Tel： 手机号码为11数字！"));

                    }
                }
                if (VD_Category.SelectedValue == "2")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, (ccc.New_Sap_Code + "").Trim(), "&nbsp;&nbsp;K2 表单 行" + i + ": 新销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 客户编号为必填"));
                }
                else if (VD_Category.SelectedValue == "3")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 原销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 客户编号为必填"));
                }
                else if (VD_Category.SelectedValue == "1")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 客户编号为必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 原销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.New_Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 新销售人员编号必填"));

                }
                else if (VD_Category.SelectedValue == "4")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K2 表单 行" + i + ": 原销售人员编号必填"));

                }
                i++;
            }
            foreach (mdc_spm_Sales_Gv_3 ccc in (List<mdc_spm_Sales_Gv_3>)this.gv_Sales_K3.DataSource)
            {
                if (string.IsNullOrEmpty(ccc.E_Mail) && string.IsNullOrEmpty(ccc.Tel) && string.IsNullOrEmpty(ccc.Sap_Code) && string.IsNullOrEmpty(ccc.Old_Sap_Code) && string.IsNullOrEmpty(ccc.New_Sap_Code))
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(ccc.E_Mail) || !string.IsNullOrEmpty(ccc.Tel))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 原销售人员编号必填"));
                }
                if (!string.IsNullOrEmpty(ccc.Tel))
                {
                    try
                    {
                        decimal length = Convert.ToDecimal(ccc.Tel.Length);
                        decimal len = Convert.ToDecimal(ccc.Tel);
                        if (length != 11)
                        {
                            regs.Add(new Regular(RegularExp.NotEmpty, (" ").Trim(), "&nbsp;&nbsp;K3 表单 行" + i + ": Tel： 手机号码为11数字！"));
                        }
                    }
                    catch (Exception)
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, (" ").Trim(), "&nbsp;&nbsp;K3 表单 行" + i + ": Tel： 手机号码为11数字！"));

                    }
                }
                if (VD_Category.SelectedValue == "2")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, (ccc.New_Sap_Code + "").Trim(), "&nbsp;&nbsp;K3 表单 行" + i + ": 新销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 客户编号为必填"));
                }
                else if (VD_Category.SelectedValue == "3")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 原销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 客户编号为必填"));
                }
                else if (VD_Category.SelectedValue == "1")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 客户编号为必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 原销售人员编号必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.New_Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 新销售人员编号必填"));

                }
                else if (VD_Category.SelectedValue == "4")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, ccc.Old_Sap_Code, "&nbsp;&nbsp;K3 表单 行" + i + ": 原销售人员或新销售人员编号必填"));

                }
                i++;
            }

            if (i == 1)
            {
                t_Attachment list = (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == TaskAPI.Incident).ListFirst<t_Attachment>();
                if (list == null)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, list, "&nbsp;&nbsp;" + "表单不能为空或者必须上传附件!"));
                }

            }
            #endregion



            return Validation(regs);
        }
        #endregion

        #region 方法 Others
        protected void VD_Payment_Methods_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private string getFormCheckList(Anthem.CheckBoxList ck)
        {
            string t = "";
            for (int i = 0; i < ck.Items.Count; i++)
                if (ck.Items[i].Selected)
                    t += "," + ck.Items[i].Value;
                else
                    t += ",";
            return t;
        }
        private Anthem.CheckBoxList setCheckList(string t, Anthem.CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion


    }
}